<link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="../../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<link rel="stylesheet" href="../../../css/layuimini.css?v=2.0.1" media="all">
<link rel="stylesheet" href="../../../css/themes/default.css" media="all">
<link rel="stylesheet" href="../../../css/public.css" media="all">
<style>
	.text-value{
		text-align: left;
		width: 70%;
		word-break:break-all;
		white-space:pre-wrap;
		cursor:auto;
	}
</style>
<div class="layuimini-main">
	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">应用成员</label>
			<div class="layui-input-block">
				<label class="layui-form-label text-value" id="showName"></label>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">角色类型</label>
			<div class="layui-input-block">
				<div id="roleType"></div>
			</div>
		</div>
		<input type="hidden" name="appId" id="appId">
		<input type="hidden" name="loginName" id="loginName">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit id="saveBtn" lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../../js/common.js" charset="utf-8"></script>
<script src="../../../js/xm-select.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
		var form = layui.form,
			layer = layui.layer,
			$ = layui.$,
			parentIndex = layer.index;
		var parentData = JSON.parse(parent.data);
		$("#appId").val(localStorage.getItem('appId_' + parent.layui.$("#userName").val()));
		$("#loginName").val(parentData.loginName);
		$("#showName").text(parentData.userName + "|" + parentData.loginName);
		var roleType = xmSelect.render({
			el: '#roleType', 
			data: [
				{name: '管理员', value: 1},
				{name: '开发', value: 2},
				{name: '测试', value: 3},
				{name: '运维', value: 4},
				{name: '架构师', value: 5},
				{name: '告警接收', value: 6},
				{name: '部署审批', value: 7}
			],
		});
		roleType.append(parentData.roleTypes);

		form.on('submit(saveBtn)', function(data) {
			$("#roleTypes").val(JSON.stringify(roleType.getValue('value')));
			data.field.roleTypes = roleType.getValue('value');
			$.ajax({
				url: '/app/member/addOrUpdate',
				type: 'POST',
				dataType: "json",
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(data.field),
				success: function(data){
					if(data.code != "000000"){
						layer.msg(data.message, {icon: 5, shift: 6});
						return false;
					}
					
					layer.msg("保存成功", {
						icon: 1,
						time: 500,
						shade: 0.01,
						shadeClose: false}, function(){
						var indexOfParent = parent.layer.getFrameIndex(window.name);
						parent.layer.close(indexOfParent);
						parent.layui.table.reload('currentTableId');
					});
				},
				error: function(data){
					layer.msg(data.message, {icon: 5, shift: 6});
				}
			});
			return false;
		});
    });
</script>